package com.dianwoba.utils;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;

/**
 * Request相关操作
 * @author licf
 */
public final class RequestUtil {
	
	private RequestUtil(){}
	
	/**
	 * 获取Nginx反向代理之后实际客户端IP
	 * @param request
	 * @return
	 */
	public static String getNginxRealIp(HttpServletRequest request) {
		if (request == null) {
			return null;
		}
		String ip = request.getHeader("X-Real-IP");
		if (StringUtils.isBlank(ip)) {
			ip = request.getRemoteAddr();
		}
		return ip;
	}

}
